$NG.AllReady(function (page, { useAction, useBeforeClick, useValuesChange, useClick, useUpdateRow, subscribe, useUpdateRows }) {
    const mstform = $NG.getCmpApi("p_form_xzykjxmgl_m")

    if(page.oType == 'add' || page.oType == 'edit'){
        const quarter = getCurrentQuarter()
        const year = new Date().getFullYear()
        $NG.updateState((updater)=>{
            updater.data.p_form_xzykjxmgl_m.setProps({
                u_nd:{
                    label:year,
                    value:year
                },
                u_jd:{
                    label:quarter.name,
                    value:quarter.value
                }
            })
        })
    }

    useValuesChange(()=>{
        getTechProjectInfo()
    },"p_form_xzykjxmgl_m.phid_pc")

    // 获取科技项目管理信息
    function getTechProjectInfo(){
        debugger
        const phid = mstform.getItem("phid_pc").getValue()
        if(!phid) return 
        $NG.execServer("getTechProjectInfo",{phid},(res)=>{
            if(res.count == 0) return 
            const datas = JSON.parse(res.data)[0].extendObjects
            $NG.updateState((updater)=>{
                updater.data.p_form_xzykjxmgl_m.setProps({
                    u_nd:{
                        label:datas.u_tbnd,
                        value:datas.u_tbnd
                    }
                })
            })
        })
    }

    // 获取当前季度
    function getCurrentQuarter() {
        const date = new Date();
        const month = date.getMonth() + 1; // 月份从0开始，所以要加1
        let quarterName, quarterValue;

        if (month >= 1 && month <= 3) {
            quarterName = "第一季度";
            quarterValue = "6870000000000382";
        } else if (month >= 4 && month <= 6) {
            quarterName = "第二季度";
            quarterValue = "6870000000000383";
        } else if (month >= 7 && month <= 9) {
            quarterName = "第三季度";
            quarterValue = "6870000000000384";
        } else {
            quarterName = "第四季度";
            quarterValue = "6870000000000385";
        }

        return {
            name: quarterName,
            value: quarterValue
        };
    }
})